<?php

$IndividualId = @$_GET['IndividualId'];
$FamilyId = @$_GET['FamilyId'];
$RedirectLocation = @$_GET['RedirectLocation'];
$RedirectArgs = @$_GET['RedirectArgs'];
$PHPSESSID = @$_GET['PHPSESSID'];


//include('../include/Indv_azlistheader.php');

        echo '<div id="page_header">'."\n";
		echo '<ul><li class="titlename2">Deleting Individual...</li>'."\n";

if($PACTS_cfg->getUserCanDelete()) {
	if(strlen($IndividualId)>0) {
		$Dusername = $PACTS_cfg->getLookValue("Individual", "IndividualId", $IndividualId, "FirstName");
		$Dusername .= " ".$PACTS_cfg->getLookValue("Individual", "IndividualId", $IndividualId, "Surname");
		mysql_query("DELETE FROM Individual WHERE IndividualId=".$IndividualId);

//        echo '<div id="page_header">'."\n";
//		echo '<ul><li class="titlename2">Deleting Individual...</li>'."\n";
		if(mysql_affected_rows()>0) {
			
			$URLmessage="Individual has been DELETED sucessfully!";
			$PACTS_cfg->InsertAuditTrailEntry( "", "" ,"Delete","Individual","COMPLETE ENTRY",$_SESSION['username'], $_SERVER['PHP_SELF'],$IndividualId." ($Dusername)");

		} else {

			$URLmessage="ERROR: Could not DELETE Individual! : ".mysql_error();

		}

			if(strlen($RedirectLocation)==0) {
				$RedirectLocation = $DefaultRedirectLocation;
			}
			
			$URL = "Location: http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF'])."/".$RedirectLocation.".php?";	$URL = $URL."FamilyId=$FamilyId&IndividualId=$IndividualId&PHPSESSID=".$PHPSESSID."&URLmessage=$URLmessage";
			if(strlen($RedirectArgs)>0) {
				$URL = $URL."&$RedirectArgs";
			}
                echo '<li class="type2">'.$URLmessage.'</li><br/>';

    		echo '<li class="type2">Click ';
            echo '<a href="index.php?view=Fmly_view&amp;'.'FamilyId='.$FamilyId.'&amp;IndividualId='.$IndividualId.'">here</a>';
            echo ' to view the Family again</li>'."\n";
            echo '</ul>'."\n";
            echo '</div>'."\n";



	} else {
		echo "Error: Could not delete record!<br /><br />";
	}
}
else {

    echo '</ul>'."\n";
	echo '<p class="errmsg1">Error! You do not have permission to delete data!</p>'."\n";
    echo '</div>'."\n";
} 



?>